#include "restore.h"

#include <stdlib.h>

#include "game.h"
#include "ws2812.h"

void Restore_Run(void) {
  /* 在此处初始化game和ws用到的flash数据 */
  Restore_ResPic();
  Restore_ResGame();
}

void Restore_ResPic(void) {
  // 初始化ws2812的图像
  hws.matrix.name[0] = '\0';
  for (uint8_t i = 0; i < 32; i++) {
    for (uint8_t j = 0; j < 8; j++) {
      hws.matrix.color[i][j][0] = 0;
      hws.matrix.color[i][j][1] = 0;
      hws.matrix.color[i][j][2] = 0;
    }
  }
  for (uint8_t idx = 0; idx < 32; idx++) {
    Ws_Save(idx);
  }
}

void Restore_ResGame(void) {
  // 初始化游戏数据
  Game_HandleTypeDef hgame;
  hgame.into = 0;
  hgame.outo = 0;
  hgame.mode = 0;
  hgame.speed = 0;
  for (uint8_t i = 0; i < 3; i++) {
    hgame.rank[i].name[0] = '\0';
    hgame.rank[i].score = 0;
  }
  hgame.user[0] = '\0';
  hgame.len = 0;
  Flash_Unlock();
  Flash_Erase(Game_addr);
  Flash_Write(Game_addr, (uint16_t*)&hgame, 512);
}
